package licode.unisop.realm.adapter.web;

import licode.unisop.client.utils.PlatformCheck;
import licode.unisop.provider.info.SiIdentityContext;
import licode.unisop.provider.info.SiReturnCode;
import licode.unisop.realm.client.api.SiIdentityService;
import licode.unisop.realm.client.info.SiIdentityRegister;
import licode.unisop.unilite.result.UniReturnResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 适配RESTFUL接口访问，处理领域的操作
 *
 * @author WR
 */
@RestController
@UniReturnResult
@RequestMapping("/user-api/v1/internal/identity")
public class IdentityController {
    @Resource
    private HttpServletRequest request;
    
    @Resource
    private PlatformCheck platformCheck;

    @Resource
    private SiIdentityService siIdentityService;

    @PostMapping("/auth")
    public SiReturnCode authUser(@RequestBody SiIdentityContext context) {
        platformCheck.checkModalToken(request);
        return siIdentityService.authUser(context);
    }

    @PostMapping("/register")
    public void registerIdentityPlugin(@RequestBody SiIdentityRegister regInfo) {
        platformCheck.checkModalToken(request);
        siIdentityService.registerIdentityPlugin(regInfo);
    }

    @PostMapping("/interceptor/register")
    public void registerIdentityInterceptor(@RequestBody SiIdentityRegister regInfo) {
        platformCheck.checkModalToken(request);
        siIdentityService.registerIdentityInterceptor(regInfo);
    }
}
